{include file='default/head' /}
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space1">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">{$title}</div>
                <div class="layui-card-body">

                    <!--                    -->
                    <div class="layui-form search">
                        <div class="layui-inline">
                            <select name="search_type" id="search_type">
                                <option value="uid">商户UID</option>
                                <option value="content">违规内容</option>
                                <option value="words">违规关键字</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <input class="layui-input" name="search_value" id="search_value" autocomplete="off"
                                   placeholder="留空查询则重载全部" value="">
                        </div>
                        <div class="layui-inline">
                            <select class="form-control" id="search_mode_type">
                                <option value="all">全部违规类型</option>
                                {foreach name="mode_list" item="v" key="key"}
                                <option value="{$key}">{$v}</option>
                                {/foreach}
                            </select>
                        </div>
                        <button class="layui-btn" data-type="reload" id="btn_search"><i
                                class="layui-icon layui-icon-search"></i> 查询
                        </button>
                    </div>
                    <!-- 表格 -->
                    <table id="data_Table" lay-filter="data_Table"></table>
                    <!-- 表格 -->

                    <script type="text/html" id="illegal_time">
                        {{#  if(d.illegal_time != "" && d.illegal_time != null){ }}
                        {{ d.illegal_time }}
                        {{#  }else{ }}
                        无
                        {{#  } }}
                    </script>
                    <script type="text/html" id="oper">
                        {{#  if(d.user_state == 0){ }}
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="state_1">封禁</a>
                        {{#  }else if(d.user_state == 1){ }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="state_0">正常</a>
                        {{#  }else{ }}
                        商户不存在
                        {{#  } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<style id="welcome_style"></style>
<div class="layui-col-md12">
    <blockquote class="layui-elem-quote layui-quote-nm">{$core['ADMIN_BOTTOM']}</blockquote>
</div>
<script>
    layui.use(['jquery', 'form', 'layedit', 'laydate', 'element', 'laytpl', 'table', 'laypage', 'layer', 'carousel', 'slider'], function () {
        $ = layui.jquery;
        var form = layui.form //表单
            , layer = layui.layer  //弹出层
            , laypage = layui.laypage //分页
            , layedit = layui.layedit  //元素操作
            , laydate = layui.laydate  //日期
            , laytpl = layui.laytpl  //模板引擎
            , table = layui.table  //表格
            , element = layui.element;
//===================数据初始化
        table.render({
            elem: '#data_Table'
            , height: 450
            , url: '/admin/Illegal/getList'
            , method: "POST"
            , page: true //开启分页
            , even: true //开启隔行背景
            , toolbar: '#data_Table_toolbar'
            , title: "表格数据"
            , cols: [[ //表头
                {field: 'id', title: 'ID', width: 10, sort: true, fixed: "left"}
                , {field: 'mode', title: '违规类型', width: 120}
                , {field: 'uid', title: '商户UID', width: 100}
                , {field: 'content', title: '违规内容', width: 240}
                , {field: 'words', title: '违规关键字', width: 180}
                , {field: 'source', title: '拦截来源', width: 120}
                , {field: 'illegal_time', title: '拦截时间', width: 170, templet: "#illegal_time"}
                , {
                    field: 'oper',
                    title: '商户状态',
                    width: 110,
                    unresize: true,
                    fixed: "right",
                    align: 'center',
                    toolbar: '#oper'
                }
            ]]
            , even: true
            , id: 'data_Table'
            , limit: 15 //每页默认显示的数量
            , limits:[]//每页条数的选择项
            , text: {
                none: '暂无数据'
            }
        });

        var $ = layui.$, active = {
            reload: function () {
                var search_type = $('#search_type').val();  //搜索类型
                var search_value = $('#search_value').val();  //搜索内容
                var search_mode_type = $('#search_mode_type').val();  //违规类型
                layer.msg('拼命查询中...', {icon: 16, shade: 0.3, time: 1500});
                //执行重载
                table.reload('data_Table', {
                    page: {
                        curr: 1 //从第 1 页开始
                    }
                    , method: "POST"
                    //额外接口参数
                    , where: {
                        mode: search_type
                        , value: search_value
                        ,type:search_mode_type
                    }
                });
            }
        };
        $("#btn_search").click(function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        })

        //操作
        table.on('tool(data_Table)', function (obj) {
            var data = obj.data;
            var event = obj.event;
            switch (event) {
                case "state_0":
                    oper(event, data.uid);
                    break;
                case "state_1":
                    oper(event, data.uid);
                    break;
                default:
                    layer.alert("不支持该操作类型")
            }
        });

        function oper(mode, uid,aqmm="") {
            var Load = layer.load(2, {shade: [0.3, '#000']}); //开始加载
            $.ajax({
                type: "POST",
                url: "/admin/userOper/oper",
                data: {"mode": mode, "uid": uid,"security_password":aqmm},
                dataType: "json",
                success: function (json) { //SUCCESS
                    var data = $.parseJSON(json);
                    if (data.code == 0) {
                        layer.close(Load); //关闭加载
                        var indexa = layer.msg(data.msg, {time: 1000, icon: 6}, function () {
                            layer.close(indexa);
                            //执行重载
                            table.reload('data_Table', {
                                page: {
                                    curr: 1 //从第 1 页开始
                                }
                                , method: "POST"
                                //额外接口参数
                                , where: {
                                    mode: "all"
                                }
                            });
                        });
                    } else {
                        layer.close(Load); //关闭加载
                        var indexa = layer.alert(data.msg, {title: data.title, icon: 5}, function () {
                            layer.close(indexa);
                            return false;
                        })
                    }
                },
                error: function () { //ERROR
                    layer.close(Load); //关闭加载
                    layer.msg('系统繁忙');
                    return false;
                }
            });
        }
    });
</script>
</body>
</html>